package com.eam.job.controller;

import com.eam.common.controller.BaseController;
import com.eam.common.domain.EamAsset;
import com.eam.common.service.IEamAssetService;
import com.eam.common.utils.ExcelUtil;
import com.eam.core.annotation.Log;
import com.eam.core.core.AjaxResult;
import com.eam.core.core.page.TableDataInfo;
import com.eam.core.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 资产Controller
 * 
 * @author eam
 * @date 2022-03-14
 */
@Api(tags = "资产接口")
@RestController
@RequestMapping("/eam/asset")
public class EamAssetController extends BaseController
{
    @Autowired
    private IEamAssetService eamAssetService;

    /**
     * 查询资产列表
     */
    @ApiOperation("资产列表")
    @PreAuthorize("@ss.hasPermi('eam:asset:list')")
    @GetMapping("/list")
    public TableDataInfo list(EamAsset eamAsset)
    {
        startPage();
        List<EamAsset> list = eamAssetService.selectEamAssetList(eamAsset);
        return getDataTable(list);
    }

    /**
     * 导出资产列表
     */
    @PreAuthorize("@ss.hasPermi('eam:asset:export')")
    @Log(title = "资产", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EamAsset eamAsset)
    {
        List<EamAsset> list = eamAssetService.selectEamAssetList(eamAsset);
        ExcelUtil<EamAsset> util = new ExcelUtil<EamAsset>(EamAsset.class);
        util.exportExcel(response, list, "资产数据");
    }

    /**
     * 获取资产详细信息
     */
    @PreAuthorize("@ss.hasPermi('eam:asset:query')")
    @GetMapping(value = "/{assetId}")
    public AjaxResult getInfo(@PathVariable("assetId") Long assetId)
    {
        return AjaxResult.success(eamAssetService.selectEamAssetByAssetId(assetId));
    }

    /**
     * 新增资产
     */
    @ApiOperation("新增资产")
    @PreAuthorize("@ss.hasPermi('eam:asset:add')")
    @Log(title = "资产", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EamAsset eamAsset)
    {
        return toAjax(eamAssetService.insertEamAsset(eamAsset));
    }

    /**
     * 修改资产
     */
    @ApiOperation("修改资产")
    @PreAuthorize("@ss.hasPermi('eam:asset:edit')")
    @Log(title = "资产", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EamAsset eamAsset)
    {
        return toAjax(eamAssetService.updateEamAsset(eamAsset));
    }

    /**
     * 删除资产
     */
    @ApiOperation("删除资产")
    @PreAuthorize("@ss.hasPermi('eam:asset:remove')")
    @Log(title = "资产", businessType = BusinessType.DELETE)
	@DeleteMapping("/{assetIds}")
    public AjaxResult remove(@PathVariable Long[] assetIds)
    {
        return toAjax(eamAssetService.deleteEamAssetByAssetIds(assetIds));
    }
}
